@echo off
call svn update

set NOCOMMIT=1
set VERSION_MAJ=3
set VERSION_MIN=8
set VERSION_NUM=1410

:Loop
IF "%1"=="" GOTO Continue
if "%1"=="nocommit" set NOCOMMIT=1
SHIFT
GOTO Loop
:Continue

svn info > nul
if errorlevel 1 goto :OnError

for /F "tokens=1,2 delims=: " %%a in ('svn info') do call :InfoProc "%%a" "%%b"
goto :end

:InfoProc
if %1=="Revision" call :WriteRevision %2
goto :end

:WriteRevision
echo #define VERSION_MAJ %VERSION_MAJ% > revision.h
echo #define VERSION_MIN %VERSION_MIN% >> revision.h
echo #define VERSION_NUM %VERSION_NUM% >> revision.h
echo #define REVISION_NUM %~1>> revision.h

goto :end

:OnError
echo Error get revision from SVN
if not "%1"=="WriteFakeHdrOnError" exit /b 1
if exist revision.h goto :end
echo generating fake header

echo #define VERSION_MAJ 0 > revision.h
echo #define VERSION_MIN 0 >> revision.h
echo #define VERSION_NUM 0 >> revision.h
echo #define REVISION_NUM 0 >> revision.h

call :WriteBody
goto :end

:end